package br.com.emersondeandrade.infraEstrutura.dao;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;

import br.com.emersondeandrade.modelo.core.casa.Casa;
import br.com.emersondeandrade.modelo.exeption.ObjectNaoEncontradoExeption;
import br.com.emersondeandrade.modelo.repositorio.CasaRepositorio;


@Repository
public class CasaDao extends DaoPadrao<Casa> implements CasaRepositorio{
	
	
	
	
	
	
	public CasaDao() {
		super(Casa.class);
	}
	
	
	
	
	public Casa getCasaByKeyArduino(String key)	throws ObjectNaoEncontradoExeption {
				
				
		TypedQuery<Casa> query = entityManager.createQuery("from Casa c where c.arduino.key = :key", Casa.class);
		
		query.setParameter("key", key);
				
		try{
			return query.getSingleResult();
		} catch (NoResultException e) {
			throw new ObjectNaoEncontradoExeption();
		}
		
		
		
	}

}
